package com.venus.finance.feetype.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.venus.common.action.BaseAction;
import com.venus.common.utils.JsonUtil;
import com.venus.finance.feetype.form.FeeTypeForm;
import com.venus.finance.feetype.service.IFeeTypeService;
import com.venus.model.FeeTypeVO;

public class FeeTypeMultiOperateAction extends BaseAction {

	private IFeeTypeService feeTypeService;
	
	public void setFeeTypeService(IFeeTypeService feeTypeService) { this.feeTypeService = feeTypeService; }

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		FeeTypeForm objFeeTypeForm = (FeeTypeForm)form;
		String strMethod = objFeeTypeForm.getMethod();
		if("getFeeSubType4Ajax".equals(strMethod)){
			return this.getFeeSubType4Ajax(mapping, objFeeTypeForm, request, response);
		}else if("getFeeType4Ajax".equals(strMethod)){
			return this.getFeeType4Ajax(mapping, objFeeTypeForm, request, response);
		}
		return super.execute(mapping, form, request, response);
	}
	
	public ActionForward getFeeSubType4Ajax(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
		String strFeeTypeId = request.getParameter("feeTypeId");
		// 支出的子类
		List<FeeTypeVO> lstFeeSubTypeVOs = this.feeTypeService.findSubFeeType(Integer.parseInt(strFeeTypeId));
		String strJson = JsonUtil.getJsonString4List(lstFeeSubTypeVOs, null);
		return this.forwardAjax(strJson, response);
	}
	
	public ActionForward getFeeType4Ajax(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
		FeeTypeForm objFeeTypeForm = (FeeTypeForm)form;
		List<FeeTypeVO> lstFeeTypeVOs = new ArrayList<FeeTypeVO>();
		if(0 == objFeeTypeForm.getFeeType()){ // 支出的子类
			lstFeeTypeVOs = this.feeTypeService.findSubFeeType(new Integer(1000));
		}else{ //收入的子类
			lstFeeTypeVOs = this.feeTypeService.findSubFeeType(new Integer(2000));
		}
		String strJson = JsonUtil.getJsonString4List(lstFeeTypeVOs, null);
		return this.forwardAjax(strJson, response);
	}
	
}
